package com.xframe.xdal.core.convert.factory;

import com.xframe.xdal.core.convert.DBConvertInfo;
import com.xframe.xdal.core.convert.IDBTypeStrategy;
import com.xframe.xdal.core.convert.imp.oracle.*;

import java.math.BigDecimal;
import java.sql.Time;

public class OracleTypeStrategyFactory implements IDBTypeStrategy {
    /**
     * @param dbConvertInfo   转换对象
     */
    @Override
    public String getDbType(DBConvertInfo dbConvertInfo) {
        if(dbConvertInfo.getJavaType().isAssignableFrom(boolean.class)){
            return new boolToDBType().getType(dbConvertInfo.getDataLength(), dbConvertInfo.getScale());
        }

        if(dbConvertInfo.getJavaType().isAssignableFrom(Integer.class)){
            return new integerToDBType().getType(dbConvertInfo.getDataLength(), dbConvertInfo.getScale());
        }

        if(dbConvertInfo.getJavaType().isAssignableFrom(BigDecimal.class)){
            return new bigDecimalToDBType().getType(dbConvertInfo.getDataLength(), dbConvertInfo.getScale());
        }

        if(dbConvertInfo.getJavaType().isAssignableFrom(Float.class)){
            return new floatToDBType().getType(dbConvertInfo.getDataLength(), dbConvertInfo.getScale());
        }

        if(dbConvertInfo.getJavaType().isAssignableFrom(Boolean.class)){
            return new boolToDBType().getType(dbConvertInfo.getDataLength(), dbConvertInfo.getScale());
        }

        if(dbConvertInfo.getJavaType().isAssignableFrom(Time.class)){
            return new dateTimeToDBType().getType(dbConvertInfo.getDataLength(), dbConvertInfo.getScale());
        }

        if(dbConvertInfo.getJavaType().isAssignableFrom(Long.class)){
            return new integerToDBType().getType(dbConvertInfo.getDataLength(), dbConvertInfo.getScale());
        }
        return new stringToDBType().getType(dbConvertInfo.getDataLength(), dbConvertInfo.getScale());
    }
}
